package com.example.jni4cpp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv = findViewById(R.id.sample_text);

        JNITest jniTest = new JNITest();
        //设置age属性
        jniTest.setAgeFromJNI(18);
        //获取age属性
        int ageFromJNI = jniTest.getAgeFromJNI();
        //logd打印age属性值
        jniTest.logFromJNI("age=" + ageFromJNI);

        Integer[] arr = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20};
        //根据关键字顺序查找在表中的存放角标
        int index = jniTest.sequenceSearchFromJNI(arr, 3);
        //如果存在返回位置index，不存在返回-1
        jniTest.logFromJNI("index=" + index);

        //显示到手机屏幕上
        tv.setText(tv.getText().toString() + "\nage=" + ageFromJNI);
        tv.setText(tv.getText().toString() + "\nindex=" + index);
    }


}
